package com.example.haojiutao.common;

import com.example.haojiutao.constant.Enum.ExceptionCodeEnum;
import lombok.Data;


/**
 * @Description: api响应结果封装类
 * @Author: wang_meiying
 * @CreateTime: 2024/1/29 19:25
 */
@Data
public class Result {
    private int code;
    private String message;
    private Object data;

    /*
     * @Description: 返回成功
     * @Author: wang_meiying
     * @CreateTime: 2024/1/29 19:25
     * @param: message
     * @return: cn.edu.nxu.musicserver.common.Result
     */
    public static Result success(String message){
        Result r = new Result();
        r.setCode(200);
        r.setMessage(message);
        return r;
    }
    public static Result success(String message, Object data){
        Result r = new Result();
        r.setCode(200);
        r.setMessage(message);
        r.setData(data);
        return r;
    }
    /*
     * @Description: 返回失败状态提示，展示原因
     * @Author: wang_meiying
     * @CreateTime: 2024/1/29 19:25
     * @param: code
     * @param: message
     * @return: cn.edu.nxu.musicserver.common.Result
     */
    public static Result faile(Integer code, String message){
        Result r = new Result();
        r.setCode(code);
        r.setMessage(message);
        return r;
    }
    /*
     * @Description: 返回失败
     * @Author: wang_meiying
     * @CreateTime: 2024/1/29 19:26
     * @param: message
     * @return: cn.edu.nxu.musicserver.common.Result
     */
    public static Result faile(String message){
        Result r = new Result();
        r.setCode(999999);
        r.setMessage(message);
        return r;
    }
    public static Result faile(ExceptionCodeEnum errorEnum) {
        Result r = new Result();
        r.setCode(errorEnum.getResCode());
        r.setMessage(errorEnum.getResDesc());
        return r;
    }
}
